/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Util;

import objectreader.test.TestMultipleModelViewer;

/**
 *
 * @author Eduardo
 */

public class AnimacaoCamera implements TimerListener
{
    double xFinal, yFinal, zFinal, incX, incY, incZ, div, cont;
    long millis;
    TestMultipleModelViewer tela;
    public Timer timer;
    public int idAnimacao = -2;

    public AnimacaoCamera (double xFinal, double yFinal, double zFinal, long millis, int idAnimacao, TestMultipleModelViewer tela)
    {
        this.cont = 0.0;
        this.div = 100.0;
        this.xFinal = xFinal;
        this.yFinal = yFinal;
        this.zFinal = zFinal;
        this.millis = millis;
        this.incX = (xFinal - tela.camX) / this.div;
        this.incY = (yFinal - tela.camY) / this.div;
        this.incZ = (zFinal - tela.camZ) / this.div;
        this.tela = tela;
        this.idAnimacao = idAnimacao;
        timer = new Timer(this, millis);
    }

    public AnimacaoCamera (double xFinal, double yFinal, double zFinal, long millis, TestMultipleModelViewer tela)
    {
        this.cont = 0.0;
        this.div = 100.0;
        this.xFinal = xFinal;
        this.yFinal = yFinal;
        this.zFinal = zFinal;
        this.millis = millis;
        this.incX = (xFinal - tela.camX) / this.div;
        this.incY = (yFinal - tela.camY) / this.div;
        this.incZ = (zFinal - tela.camZ) / this.div;
        this.tela = tela;
        timer = new Timer(this, millis);
    }

    public void movimentar()
    {
        timer.start();
    }


    public void update(long millis)
    {
        if (this.idAnimacao == -2)
        {
            if (cont == div)
            {
                timer.finalizar();
            }
            else
            {
                tela.camX += incX;
                tela.camY += incY;
                tela.camZ += incZ;
                cont += 1.0;
                tela.repaint();
            }
        }
        else
        {
            if (cont == div)
            {
                timer.finalizar();
                tela.cameraSendoMovida = -1;
            }
            else if ((tela.cameraSendoMovida == -1) || (tela.cameraSendoMovida == this.idAnimacao))
            {
                tela.cameraSendoMovida = this.idAnimacao;
                tela.camX += incX;
                tela.camY += incY;
                tela.camZ += incZ;
                cont += 1.0;
                tela.repaint();
            }
        }
    }

}
